﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using ApplLogic.ApplClasses;
using TCPClient.UI.LogicForUserControls;

namespace TCPClient.UI
{
    public partial class PersonalDetailsOfWorkerForManager : Form
    {
        private ApplWorker m_Worker = null;
        public PersonalDetailsOfWorkerForManager(ApplWorker worker)
        {
            m_Worker = worker;
            InitializeComponent();
            setButtonVisibility();
            showWorkerData();
        }

        private void setButtonVisibility()
        {
            buttonShowStatWeekly.Enabled = ScMainUserControlLogicManager.Instance.GetWorkerStat(
                ScMainUserControlLogicManager.Instance.StartTimeOfTheWeek.AddHours(-1), ScMainUserControlLogicManager.Instance.EndTimeOfTheWeek.AddHours(1), m_Worker.PersonalDetails.Id) != null;
        }

        private void showWorkerData()
        {
            textBoxFirstName.Text = m_Worker.PersonalDetails.FirstName;
            textBoxLastName.Text = m_Worker.PersonalDetails.LastName;
            textBoxId.Text = m_Worker.PersonalDetails.Id;
            textBoxMailFirst.Text = m_Worker.PersonalDetails.EmailAdress.Split('@')[0];
            textBoxMailSecond.Text = m_Worker.PersonalDetails.EmailAdress.Split('@')[1];
            textBoxDateYear.Text = m_Worker.PersonalDetails.BirthDate.Year.ToString();
            textBoxDateMonth.Text = m_Worker.PersonalDetails.BirthDate.Month.ToString();
            textBoxDateDay.Text = m_Worker.PersonalDetails.BirthDate.Day.ToString();
            textBoxSOFYear.Text = m_Worker.StartOfWork.Year.ToString();
            textBoxSOFMounth.Text = m_Worker.StartOfWork.Month.ToString();
            textBoxSOFDay.Text = m_Worker.StartOfWork.Day.ToString();
            textBoxMaxShiftNumber.Text = m_Worker.MaxShiftsThatCanGive.ToString();
        }

        public void ShowWorkerRequestedAndREgistered()
        {
            this.labelWeekDates.Text = string.Format("{0} {1} - {2}", "Week:", 
                ScMainUserControlLogicManager.Instance.StartTimeOfTheWeek.ToShortDateString(),
                              ScMainUserControlLogicManager.Instance.EndTimeOfTheWeek.ToShortDateString());
            this.dataGridViewRegisteredFirst.DataSource = ScMainUserControlLogicManager.Instance.GetAllRegisteredShifsOfWorkerWithType(m_Worker.PersonalDetails.Id,
                                                                                      eResult.FIRST);
            dataGridViewRegisteredFirst.Columns[0].Visible = false;
            dataGridViewRegisteredFirst.Columns[2].HeaderText = @"Capacity";
            this.dataGridViewRegisteredSecond.DataSource = ScMainUserControlLogicManager.Instance.GetAllRegisteredShifsOfWorkerWithType(m_Worker.PersonalDetails.Id,
                                                                                      eResult.SECOND);
            dataGridViewRegisteredSecond.Columns[0].Visible = false;
            dataGridViewRegisteredSecond.Columns[2].HeaderText = @"Capacity";
            this.dataGridViewRegisteredThird.DataSource = ScMainUserControlLogicManager.Instance.GetAllRegisteredShifsOfWorkerWithType(m_Worker.PersonalDetails.Id,
                                                                                      eResult.THIRD);

            dataGridViewByManager.DataSource = ScMainUserControlLogicManager.Instance.GetAllRegisteredShifsOfWorkerWithType(m_Worker.PersonalDetails.Id,
                                                                                      eResult.BYMANAGER);
            dataGridViewByManager.Columns[0].Visible = false;
            dataGridViewByManager.Columns[2].HeaderText = @"Capacity";

            dataGridViewRegisteredThird.Columns[0].Visible = false;
            dataGridViewRegisteredThird.Columns[2].HeaderText = @"Capacity";
            this.dataGridViewRequestedWanted.DataSource = ScMainUserControlLogicManager.Instance.GetAllRequestedShiftsOfWorkerWithType(m_Worker.PersonalDetails.Id,
                                                                                      eType.WANTED);
            dataGridViewRequestedWanted.Columns[0].Visible = false;
            dataGridViewRequestedWanted.Columns[2].HeaderText = @"Capacity";
            this.dataGridViewRequestedForbidden.DataSource = ScMainUserControlLogicManager.Instance.GetAllRequestedShiftsOfWorkerWithType(m_Worker.PersonalDetails.Id,
                                                                                      eType.FORBIDDEN);
            dataGridViewRequestedForbidden.Columns[0].Visible = false;
            dataGridViewRequestedForbidden.Columns[2].HeaderText = @"Capacity";
        }

        private void show(object obj)
        {
            (obj as WorkerStatForm).ShowDialog();
        }

        private void buttonShowStat_Click_1(object sender, EventArgs e)
        {
            WorkerStatForm wsf = new WorkerStatForm(ScMainUserControlLogicManager.Instance, m_Worker.PersonalDetails.Id, eStatType.Weekly);
            Thread th = new Thread(show);
            th.Start(wsf);
        }

        private void buttonStatAggr_Click(object sender, EventArgs e)
        {
            WorkerStatForm wsf = new WorkerStatForm(ScMainUserControlLogicManager.Instance, m_Worker.PersonalDetails.Id, eStatType.Aggregative);
            Thread th = new Thread(show);
            th.Start(wsf);
        }


    }
}
